<?php
// start the session
ini_set('display_errors', 'On');
error_reporting(E_ALL);
session_start();



/*(25-01-2010)======setting up the web root and server root for this web site =========*/


$thsfile = str_replace('\\', '/', __FILE__);

if(isset($_SERVER['DOCUMENT_ROOT'])){
	$droot = $_SERVER['DOCUMENT_ROOT'];
}
else{
	$localpath = getenv("SCRIPT_NAME");
	$absolutepath = realpath(basename(getenv("SCRIPT_NAME")));
	
	/*==== fix for Windows slashes ======*/
	$absolutepath = str_replace("\\","/",$absolutepath);	
	$droot = substr($absolutepath,0,strpos($absolutepath,$localpath));
}

 if(!isset($sp))	
  	$sp=explode("/",$_SERVER['PHP_SELF']);

  if($_SERVER['HTTP_HOST'] == "localhost" || $_SERVER['HTTP_HOST'] == "192.168.1.61")
   {
	  $sp[1] = '/' . $sp[1];
   }
  else
	  $sp[1] = '';
  
  $w_root = $_SERVER['SERVER_NAME'] . $sp[1];
  $w_root = str_replace('//','/',$w_root);
  $w_root = str_replace('\\\\','\\',$w_root);
  
  $s_root = $_SERVER['DOCUMENT_ROOT'] . $sp[1];
  $s_root = str_replace('//','/',$s_root);
  $s_root = str_replace('\\\\','\\',$s_root); 
  
 define('W_ROOT', "http://" . $w_root);
 define('S_ROOT', $s_root);
/*========End Setting up web root and server root =============*/

// Function Change URL
function url($domain, $url, $rules) {
    $url = parse_url($url);
    parse_str($url['query'], $url['query']);
    $argNames = array_keys($url['query']);
    foreach ($rules as $rule) {
        if ($rule[0] == $url['path'] && array_keys($rule[1]) == $argNames) {
            $newUrl = $rule[2];
            foreach ($rule[1] as $name => $pattern) {
                if (!preg_match('/'.addcslashes($pattern, '/').'/', $url['query'][$name], $match)) {
                    continue 2;
                }
                $newUrl = str_replace('<'.$name.'>', $match[0], $newUrl);
            }
            return $domain.$newUrl;
        }
    }
    return $url;
}
// End Function Change URL
define('TMP_ADMIN_PATH', S_ROOT . '/templates/admin_template.php');
define('TMP_USER_PATH', S_ROOT . '/templates/template.php');

define('W_IMAGES_DIR', W_ROOT.'/images/');
define('S_IMAGES_DIR', S_ROOT.'/images/');


define('ACCEPT_IMAGE_EXT', ".jpg,.png,.ping,.jpeg,.gif");
define('ACCEPT_FILE_EXT', ".jpg,.png,.ping,.jpeg,.gif,.pdf,.doc,.flv,.zip,.rar");
define('MAX_UPLOAD_SIZE', 1048576);
define('MAX_UPLOAD_FILE_SIZE', 3145728);
define('MAX_THUM_IMG_W', 100);
define('MIN_THUM_IMG_W', 75);
define('MAX_SMALL_IMAGE_WIDTH', 500);

// do we need to limit the product image width?
// setting this value to 'true' is recommended
define('LIMIT_PRODUCT_WIDTH',     true);

// maximum width for all product image
define('MAX_PRODUCT_IMAGE_WIDTH', 500);

// the width for product thumbnail
define('THUMBNAIL_WIDTH',         150);
define('LIMIT_COMPANY_W', true);
// maximum width for all company image
define('MAX_COMPANY_IMG_W', 200);
define('MAX_COMPANY_THUMBIMG_W', 75);

define('NO_IMAGES_W', W_IMAGES_DIR.'no_image_small.jpg');
define('NO_IMAGES_S', S_IMAGES_DIR.'no_image_small.jpg');

define('UPLOAD_DIR','images/');
define('MENU_IMG_DIR',UPLOAD_DIR. 'menus/');
define('CONTENT_IMG_DIR',UPLOAD_DIR. 'contents/');



//Define note text of require field
define('STAR_T','<span class="note">*</span>');
//Array of the user title
define('POINT','<img src=\"W_IMAGES_DIR /images/point.jpg\"/>');

/*===== String Define ===========*/
$mosConfig_live_site = W_ROOT;
$mosConfig_absolute_path = S_ROOT;
$mosConfig_sitename = 'Website';
//$logoConfig_sitename = 'Savemylife-Logo-01.png';


  $site_title 		= isset($site_title) ? $site_title : 'KHM.CO';
  $site_description	= isset($site_description)? $site_description : "";
  $site_keywords	= isset($site_keywords) ? $site_keywords : "";

/*===== End String Define ===========*/
define('MAX_RECORD_DISPLAY', 15);

//Number of display News on homepage
define('MAX_NEWS_DISPLAYH', 10);

//Display # of record per page
define('DISPLAY_NUMBER', '5,10,15,20,25,30,50');



/*=======Require Other Function Section Area==================*/
require_once 'db-funct.php';
require_once 'common-funct.php';
//require_once 'joomla-funct.php';
require_once 'admin-funct.php';

/*=======End Require Other Function Section Area==================*/

// check user
if(preg_match("/admin/", $_SERVER['PHP_SELF']))
 {
checkAdminUser(); 
 }
 
if(preg_match("/buyer/", $_SERVER['PHP_SELF']))
 {
checkBuyerUser(); 
 } 
 if(preg_match("/seller/", $_SERVER['PHP_SELF']))
 {
checkSellerUser(); 
require_once 'seller.class.php';
 }
?>